home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / python-support / python-rdflib / rdflib / syntax / serializers / NTSerializer.py < prev    next >
Encoding:
Python Source  |  2007-04-04  |  718 b   |  20 lines

  1. #$Id: NTSerializer.py,v 1.6 2003/10/29 15:25:24 kendall Exp $
  2.  
  3. from rdflib.syntax.serializers import Serializer
  4.  
  5. class NTSerializer(Serializer):
  6.  
  7.     def __init__(self, store):
  8.         """
  9.         I serialize RDF graphs in NTriples format.
  10.         """
  11.         super(NTSerializer, self).__init__(store)
  12.  
  13.     def serialize(self, stream, base=None, encoding=None, **args):
  14.         if base is not None:
  15.             print "TODO: NTSerializer does not support base"
  16.         encoding = self.encoding
  17.         write = lambda triple: stream.write((triple[0].n3() + u" " + \
  18.                                              triple[1].n3() + u" " + triple[2].n3() + u".\n").encode(encoding, "replace"))
  19.         map(write, self.store)
  20.